package FirstProject;

import java.util.concurrent.Callable;
//话痨套餐
public class TalkPackage extends ServicePackage implements CallService ,SendService {
    int talkTime = 500;
    int smsCount = 30;//短信条数
    double price = 58;


    public TalkPackage(double price) {
        super(58);
        this.talkTime = talkTime;
        this.smsCount = smsCount;
        this.price = price;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void showInfo() {
        System.out.println("当前套餐为话痨套餐"+price+"元/月"+ ",可免费通话时长为:" +
                talkTime + ",可免费发送的信息总数为:" + smsCount);
    }

    @Override
    public int call(int minCount, MobileCard card) {
        int extra=0;//超出的
        if(minCount<=talkTime){
            talkTime-=minCount;
        }else {
            extra=minCount-talkTime;
            talkTime=0;
            card.consumeAmount+=extra*0.2;
        }
        card.realTalkTime+=minCount;
        return extra;
    }

    @Override
    public int send(int count, MobileCard card) {
        int extra=0;
        if(count<=smsCount){
            smsCount-=extra;
        }else{
            extra=count-smsCount;
            smsCount=0;
            card.consumeAmount+=extra*0.1;
        }
        card.realSMSCount+=count;
        return extra;
    }
}
interface CallService {//最小计数
  int call(int minCount,MobileCard card);
}
